package com.itheima.edu.manager.service;

import com.itheima.edu.manager.dao.StudentDao;
import com.itheima.edu.manager.domain.Student;

public class StudentService {


    private StudentDao studentDao = new StudentDao();


    public boolean addStudent(Student student) {
        return studentDao.addStudent(student);
    }

    public boolean isExists(String id) {

        Student[] student = studentDao.findAllStudent();

        boolean exists = false;
        for (int i = 0; i < student.length; i++) {
            Student stus = student[i];
            if (stus != null && stus.getId().equals(id)) {
                exists = true;
                break;

            }
        }
        return exists;
    }

    public Student[] findAllStudent() {
        Student[] allStudent = studentDao.findAllStudent();
        boolean flag=false;
        for (int i = 0; i < allStudent.length; i++) {
            Student student = allStudent[i];
            if (null!=student) {
                flag=true;
                break;
            }
        }
        if (flag) {
            return allStudent;
        }else return null;
    }

    public void deleteStudentById(String deleteID) {
        studentDao.deleteStudentById(deleteID);
    }

    public void updateStudent(String updateID, Student newStudent) {

        studentDao.updateStudent(updateID,newStudent);
    }
}
